package org.budo.netty.servlet.server.resource.loader;

import java.io.File;

import org.budo.netty.servlet.server.resource.Resource;

/**
 * @author lmw
 */
public class BudoFileResourceLoader implements ResourceLoader {
    private String path;

    public BudoFileResourceLoader(String path) {
        this.path = path;
    }

    @Override
    public Resource getResource(String location) {
        if (null == this.path || null == location) {
            return null;
        }

        File file = new File(this.path + File.separator + location);
        if (!file.exists() || !file.isFile() || !file.canRead()) {
            return null;
        }

        return new FileResource(file);
    }
}